Skip to content

test(demo): disable git auto-maintenance in the request source sandbox - #1174

Draft
sbalabanov wants to merge 1 commit into
mainfrom
sergeyb/test-demo-request-source-no-maintenance
Draft

sbalabanov wants to merge 1 commit into
mainfrom
sergeyb/test-demo-request-source-no-maintenance

Conversation

@sbalabanov

@sbalabanov sbalabanov commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

TLDR: A demo test helper could occasionally fail its temp-directory cleanup because git was still maintaining the repository in the background, so we switch that maintenance off in the helper.

Summary

The sandbox helper in service/submitqueue/demo/requests/source_test.go creates a bare repository and seed clones under t.TempDir(), and the code under test pushes branches into it (TestGitSource_SerializesConcurrentChanges pushes five). A push or commit can trigger git's automatic background maintenance, which repacks the repository and can still be writing after the test returns. TempDir cleanup then races it and can fail with "directory not empty".

The fix sets maintenance.auto=false on the bare repository and on each seed clone (in sandbox and in TestCheckFoldersHaveTargets), so no push or commit in those repositories starts background maintenance while cleanup removes them. The source's own working clone lives outside t.TempDir() and is left alone. This matches tool/gitsandbox, which the helper stands in for. Test-only change; no production code is touched.

Test Plan

Run from the repository root:

  • ./tool/bazel test //service/submitqueue/demo/requests:go_default_test passed.
  • ./tool/bazel test //service/submitqueue/demo/requests:go_default_test --runs_per_test=50 --runs_per_test_detects_flakes --nocache_test_results passed, 50 of 50.
  • The same 50-run command with 16 busy-loop processes running beside it passed, 50 of 50.
  • make lint, make check-gazelle and make check-tidy passed.

The race is host-timing dependent and was not reproduced before the fix, so the stress runs show no regression rather than a before/after delta.

🤖 Generated with Claude Code

@sbalabanov sbalabanov left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[flaky-1-f2c-reviewer] nit: two wording fixes in the commit message and PR body.

  • The commit message says "automatic background maintenance (gc)". In the pinned git 2.55.0, unscheduled auto-maintenance uses the geometric strategy (builtin/gc.c:1964-1974), so the process that writes is a geometric repack, not gc. Drop "(gc)" or say "(a repack)". The PR body already leaves it out.
  • "no push or commit starts a background process" (commit message) and "so nothing runs in the background while cleanup removes the directories" (PR body) claim too much. The source's own working clone (git.go:60, created with os.MkdirTemp outside t.TempDir) still starts auto-maintenance after its fetches and commits. That is harmless, because close ignores removal errors, and is why the clone is left alone. Limit the claim to the repositories you configure, for example "no push or commit into them starts one".

[flaky-1-f2c-reviewer] nit: the Test Plan's stress runs are 50, plus 50 under load. F2c's acceptance command is --runs_per_test=200 --runs_per_test_detects_flakes --nocache_test_results --local_test_jobs=32. Either run it or say why 50 is enough. Neither count can tell a fixed fixture from an unfixed one, because the natural failure rate is far too low, and the Test Plan's last sentence says so honestly. I still find the validation adequate, because the mechanism carries it:

  • In 2.55.0, every auto-maintenance entry point goes through prepare_auto_maintenance (run-command.c:1956-1967), which returns early when maintenance.auto=false. The entry points are commit, fetch, merge, rebase, am and receive-pack.
  • gitexec drops system and global config but still reads repo-local config.
  • Forcing the same repack in the runway git merger fixture went from failures to none once this setting was added.

For direct evidence on this fixture, run the throwaway forcing experiment and record it as a described experiment: config maintenance.geometric-repack.auto -1 on bare, --runs_per_test=20, first without the fix and then with it.

No must-fix. Every repository the file creates under t.TempDir gets maintenance.auto=false before its first command that can start maintenance. That covers each sandbox bare and seed (two of each in TestCheckFoldersHaveTargets) and that test's extra seed. For a seed, the first such command is its commit; for a bare, it is the first push into it. clone, client-side push and cat-file start no maintenance. The test style matches the surrounding lines, there are no internal names, the change touches only F2c's file, and the branch is based on current main.

The sandbox helper builds a bare repository and seed clones under
t.TempDir and the code under test pushes several branches into it
(TestGitSource_SerializesConcurrentChanges pushes five). A push can
trigger git's automatic background maintenance, which repacks the
repository and can still be writing after the test returns. TempDir
cleanup then races it and can fail with 'directory not empty'.

Setting maintenance.auto=false on the bare repository and on each seed
clone means no push or commit in those repositories starts background
maintenance, so nothing writes into them while cleanup removes them.
The source's own working clone lives outside t.TempDir and is left
alone. This matches tool/gitsandbox, which the helper stands in for.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@sbalabanov
sbalabanov force-pushed the sergeyb/test-demo-request-source-no-maintenance branch from 094a6d8 to bf1edd8 Compare December 3, 2026 21:21

@sbalabanov sbalabanov left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[flaky-1-f2c-reviewer] satisfied: the new comment names the race in one line, the commit message and PR body now say repack and limit the claim to the configured repositories, and the only code change since round 1 is that comment. The Test Plan nit stays a nit: the validation rests on the mechanism.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant